package cn.crm;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.sql.Types;
import java.util.Collections;

public class Generator {
    public static void main(String[] args) {
        System.out.println("189823");
        FastAutoGenerator.create("jdbc:mysql:///s53-crm-clue?serverTimezone=GMT-8","root","root")
        .globalConfig(builder -> {
            builder.author("baomidu")//设置作者
                    .enableSwagger()//开启swagger模式
                    .fileOverride()//覆盖已经生成的文件
                    .outputDir("D://code");//指定输出目录
        }).dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
            int typeCode=metaInfo.getJdbcType().TYPE_CODE;
            if(typeCode== Types.SMALLINT){
                //自定义类型转换
                return DbColumnType.INTEGER;
            }
            return typeRegistry.getColumnType(metaInfo);
        }))
                .packageConfig(builder -> {
                    builder.parent("com.crm")//设置父包名
                    .moduleName("clue")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,"D://code"));//设置mapper.xml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("tb_clue")//设置需要生成的表名
                    .addTablePrefix("tb_","c_");//设置过滤表前缀
                })
                .execute();
    }
}
